package com.example.medical.controller.leadership;

import com.example.medical.entity.dto.LeadershipSaveStoreroomDto;
import com.example.medical.entity.dto.LeadershipUpdateStoreroomDto;
import com.example.medical.entity.dto.UserGetStoreroomListDto;
import com.example.medical.service.StoreroomService;
import com.example.medical.utils.common.enums.Code;
import com.example.medical.utils.common.result.Result;
import com.example.medical.utils.config.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/leadership/storeroom")
public class LeadershipStoreroomController {

    @Autowired
    private StoreroomService storeroomService;

    @PostMapping("/get_storeroom_list")
    public Result LeadersGetStoreroomList(@RequestBody UserGetStoreroomListDto dto){
        return storeroomService.UserGetStoreroomList(dto);
    }

    @GetMapping("/get_storeroom_detail")
    public Result LeadershipGetStoreroomDetail(@RequestParam("id")Long id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        return Result.okResult(storeroomService.getById(id));
    }

    @GetMapping("/remove_storeroom")
    public Result LeadersRemoveStoreroom(@RequestParam("id") Long id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
            boolean checkRemove = storeroomService.removeById(id);
            if (!checkRemove) {
                return Result.errorResult(Code.SERVER_ERROR);
            }
        return Result.okResult(Code.SUCCESS);
    }

    @PostMapping("/save_storeroom")
    public Result LeadershipSaveStoreroom(@RequestBody LeadershipSaveStoreroomDto dto){
        return storeroomService.LeadershipSaveStoreroom(dto);
    }

    @GetMapping("/update_get_storeroom_detail")
    public Result LeadershipUpdateGetStoreroom(@RequestParam("id") Long id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        return Result.okResult(storeroomService.getById(id));
    }

    @PostMapping("/update_storeroom")
    public Result LeadershipUpdateStoreroom(@RequestBody LeadershipUpdateStoreroomDto dto){
        return storeroomService.LeadershipUpdateStoreroom(dto);
    }

    @GetMapping("/remove_storeroom_arr")
    public Result LeadershipRemoveStoreroomArr(@RequestParam("ids")String[] ids){
        return storeroomService.LeadershipRemoveStoreroomArr(ids);
    }

}
